package com.morehair.controller.wx;

import com.morehair.bean.bo.wx.OrderCommentBo;
import com.morehair.bean.bo.wx.OrderSubmitBo;
import com.morehair.bean.bo.wx.WxOrderCancelBo;
import com.morehair.bean.pojo.OrderGoods;
import com.morehair.bean.vo.admin.BaseRespVo;
import com.morehair.bean.vo.wx.WxOrderDetailVo;
import com.morehair.bean.vo.wx.WxOrderInfoListVo;
import com.morehair.bean.vo.wx.WxOrderSubmitVo;
import com.morehair.bean.vo.wx.WxPayInfoVo;
import com.morehair.service.wx.WxOrderService;
import com.morehair.utils.GetNowUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author raohui
 * @Date 2021/6/9 19:09
 */
@RestController
@RequestMapping("wx/order")
public class WxOrderController {


    @Autowired
    WxOrderService wxOrderService;

    //rao
    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody OrderSubmitBo orderInfo) {
        Integer orderId = wxOrderService.submitOrder(orderInfo);
        if (orderId == null) {
            return BaseRespVo.ok((int)(Math.random()*20));
           // return BaseRespVo.fail(-1, null,"服务器繁忙,请稍后再试试！");
        }
        WxOrderSubmitVo wxOrderSubmitVo = new WxOrderSubmitVo(orderId);
        return BaseRespVo.ok(wxOrderSubmitVo);
    }

    //rao
    @RequestMapping("prepay")
    public BaseRespVo prepay() {
        //return BaseRespVo.fail(724,"订单不能支付");
        return BaseRespVo.ok( new WxPayInfoVo(), "success");
    }

    //rao
    @RequestMapping("list")
    public BaseRespVo list(Integer showType, Integer page, Integer size) {

        Integer userId = GetNowUser.getUser().getId();

        WxOrderInfoListVo list = wxOrderService.getOrderList(showType, page, size, userId);

        return BaseRespVo.ok(list);
    }


    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId) {
        WxOrderDetailVo info = wxOrderService.getOrderDetail(orderId);
        return BaseRespVo.ok(info);
    }

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody OrderCommentBo orderInfo) {
        wxOrderService.addComment(orderInfo);
        return BaseRespVo.ok();
    }


    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody WxOrderCancelBo orderId) {
        wxOrderService.cancelOrder(orderId.getOrderId());
        return BaseRespVo.ok();
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody WxOrderCancelBo refund) {
        wxOrderService.refundOrder(refund.getOrderId());
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody WxOrderCancelBo orderId) {
        wxOrderService.deleteOrder(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody WxOrderCancelBo orderId) {
        wxOrderService.confirmOrder(orderId);
        return BaseRespVo.ok();
    }

    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId, Integer goodsId) {
        OrderGoods data = wxOrderService.getOrderGoods(orderId, goodsId);
        return BaseRespVo.ok(data);
    }


}
